﻿using MahApps.Metro.Controls;
using System;
using System.Windows;
using System.Windows.Input;

namespace ACC.Extensions.PCClient.View
{
    /// <summary>
    /// Interaction logic for UserLoginWnd.xaml
    /// </summary>
    public partial class UserLoginWnd : MetroWindow
    {
        public UserLoginWnd()
        {
            InitializeComponent();
            this.Owner = Application.Current.MainWindow;
            this.KeyDown += WndFocusPreviewKeyDown;
            this.txtEmployeeCode.Focus();
        }
        public string OperatorId { get; set; }
        private void btnLogin_Click(object sender, RoutedEventArgs e)
        {
            if (string.IsNullOrEmpty(txtEmployeeCode.Text))
            {
                return;
            }
            OperatorId = txtEmployeeCode.Text;
            DialogResult = true;
            this.Close();
        }

        private void btnCancel_Click(object sender, RoutedEventArgs e)
        {
            DialogResult = false;
            this.Close();
        }

        private void txtEmployeeCode_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.Key != Key.Enter)
            {
                return;
            }
            if (string.IsNullOrEmpty(txtEmployeeCode.Text))
            {
                return;
            }
            OperatorId = txtEmployeeCode.Text;
            DialogResult = true;
            this.Close();

        }

        private void WndFocusPreviewKeyDown(object sender, KeyEventArgs e)
        {
            Dispatcher.BeginInvoke(new Action(() =>
            {
                this.txtEmployeeCode.Focus();
            }));
        }

    }
}
